﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Data
{
   public class UsuarioDAL
    {

        private const string CONNECTION_STRING =
           @"Data Source=SC-NOTEBOOK\SQLEXPRESS;Initial Catalog=dbOttado;Integrated Security=True";
        private const string SOCIO = "uspValidaUser";

        public bool validaSocio(string usr, string pass)
        {

           
            using (var con = new SqlConnection())
            {
                try
                {
                    con.ConnectionString = CONNECTION_STRING;
                    con.Open();
                    var socio = new SqlCommand
                    {
                        Connection = con,
                        CommandType = CommandType.StoredProcedure,
                        CommandText = SOCIO,
                        CommandTimeout = 100
                    };
                    socio.Parameters.AddWithValue("@usr", usr.ToString());
                    socio.Parameters.AddWithValue("@pass", pass.ToString());
                    var cantSocios = socio.ExecuteScalar();
                    if (Convert.ToInt32(cantSocios) == 1)
                    { return true; }
                    else
                    { return false; }
                }
                catch (Exception)
                {
                    return false;

                }
                finally
                {
                    if (con.State != ConnectionState.Closed)
                    {
                        con.Close();
                    }
                }
                
            
            }
        
        }
    }
}
